package cn.pconline.autoclub.web.wap;

import cn.pconline.autoclub.config.SystemConfig;
import cn.pconline.autoclub.entity.ClubMember;
import cn.pconline.autoclub.entity.User;
import cn.pconline.autoclub.service.MemberService;
import cn.pconline.autoclub.web.UserAuth;
import cn.pconline.r.client.SimpleHttpTemplate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/wap/task")
public class TaskAction {

    @Autowired
    private UserAuth userAuth;
    @Autowired
    private MemberService memberService;
    @Autowired
    private SimpleHttpTemplate simpleHttpTemplate;
    @Autowired
    private SystemConfig systemConfig;

    private String getLoginUrl(String returnUri) {
        return systemConfig.getUcWapRoot() + "/passport/login.jsp?return=" + systemConfig.getWapRoot() + returnUri;
    }

    @RequestMapping(value = "/listTask")
    public String listTask(HttpServletRequest request, HttpServletResponse response) {
        // 判断用户是否登录
        User userLogin = userAuth.getUser(request, response);
        if (userLogin == null || userLogin.getUid() == 0L) {
            return "redirect:" + getLoginUrl("/task/");
        }
        ClubMember mem = memberService.findClubMemberByUserId(userLogin.getUid());
        request.setAttribute("isMember", mem != null);
        return "template/wap/task/taskList";
    }
}
